package day4

object Test5_flatten {
  def main(args: Array[String]): Unit = {
    val list = List(List(1, 2, 3), List(5, 6, 7))
    // 效果就是将集合中的每个元素的子元素映射到某个函数并返回新的集合
    val list2: List[Int] = list.flatten
    for (elem <- list2) {
      println(elem)
    }
    val list3 = List("yusheng","wang","jun")
    val list4 = list3.flatten
    for (elem <- list4) {
      println(elem)
    }

    val arr1 = Array[String]("zhangsan,lisi","wangwu,zhoaliu","hengqi,shuba")
    val arr2 = arr1.flatMap(k => k.split(","))
    for (elem <- arr2) {
      println(elem)
    }
  }
}
